<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>通过socket进行本地的进程间通信 | ACBS</title><meta name="keywords" content="python,socket"><meta name="author" content="boshen"><meta name="copyright" content="boshen"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="我的一个python程序需要写一个界面,最终定的是逻辑使用python,界面使用electron进行开发,electron的逻辑是由node来解释执行的,所以我把python作为node的一个子线程,node进程和python进程之间使用socket进行通信. 需求我需要一个进程等待另一个进程下达指令,接收到指令后,分析并执行,然后给出返回值     原理socket的原理简单来说,就是插头和插座">
<meta property="og:type" content="article">
<meta property="og:title" content="通过socket进行本地的进程间通信">
<meta property="og:url" content="http://www.acbs.top/new/2021/02/06/%E9%80%9A%E8%BF%87socket%E8%BF%9B%E8%A1%8C%E6%9C%AC%E5%9C%B0%E7%9A%84%E8%BF%9B%E7%A8%8B%E9%97%B4%E9%80%9A%E4%BF%A1/index.html">
<meta property="og:site_name" content="ACBS">
<meta property="og:description" content="我的一个python程序需要写一个界面,最终定的是逻辑使用python,界面使用electron进行开发,electron的逻辑是由node来解释执行的,所以我把python作为node的一个子线程,node进程和python进程之间使用socket进行通信. 需求我需要一个进程等待另一个进程下达指令,接收到指令后,分析并执行,然后给出返回值     原理socket的原理简单来说,就是插头和插座">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://www.acbs.top/new/img/orange.jpg">
<meta property="article:published_time" content="2021-02-06T10:43:58.000Z">
<meta property="article:modified_time" content="2021-02-13T01:44:31.487Z">
<meta property="article:author" content="boshen">
<meta property="article:tag" content="python">
<meta property="article:tag" content="socket">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://www.acbs.top/new/img/orange.jpg"><link rel="shortcut icon" href="/new/img/favicon.png"><link rel="canonical" href="http://www.acbs.top/new/2021/02/06/%E9%80%9A%E8%BF%87socket%E8%BF%9B%E8%A1%8C%E6%9C%AC%E5%9C%B0%E7%9A%84%E8%BF%9B%E7%A8%8B%E9%97%B4%E9%80%9A%E4%BF%A1/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/new/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/new/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isanchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = { 
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2021-02-13 09:44:31'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    })(window)</script><link rel="stylesheet" href="//at.alicdn.com/t/font_2373087_elarzsy8l6s.css"><meta name="generator" content="Hexo 5.3.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" src="/new/img/touxiang.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/new/archives/"><div class="headline">文章</div><div class="length-num">12</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/new/tags/"><div class="headline">标签</div><div class="length-num">7</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/new/categories/"><div class="headline">分类</div><div class="length-num">2</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/new/archives/"><i class="fa-fw fa fa-clock"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/new/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/new/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/new/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></div><div class="menus_item"><a class="site-page" href="/new/photo/"><i class="fa-fw fas fa-images"></i><span> 图片</span></a></div><div class="menus_item"><a class="site-page" href="/new/start/"><i class="fa-fw fa fa-location-arrow"></i><span> 起始页</span></a></div><div class="menus_item"><a class="site-page" href="/new/link/"><i class="fa-fw fas fa-link"></i><span> 友情链接</span></a></div><div class="menus_item"><a class="site-page" href="/new/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="not-top-img" id="page-header"><nav id="nav"><span id="blog_name"><a id="site-name" href="/new/">ACBS</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/new/archives/"><i class="fa-fw fa fa-clock"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/new/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/new/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/new/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></div><div class="menus_item"><a class="site-page" href="/new/photo/"><i class="fa-fw fas fa-images"></i><span> 图片</span></a></div><div class="menus_item"><a class="site-page" href="/new/start/"><i class="fa-fw fa fa-location-arrow"></i><span> 起始页</span></a></div><div class="menus_item"><a class="site-page" href="/new/link/"><i class="fa-fw fas fa-link"></i><span> 友情链接</span></a></div><div class="menus_item"><a class="site-page" href="/new/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav></header><main class="layout" id="content-inner"><div id="post"><div id="post-info"><h1 class="post-title">通过socket进行本地的进程间通信</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-02-06T10:43:58.000Z" title="发表于 2021-02-06 18:43:58">2021-02-06</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2021-02-13T01:44:31.487Z" title="更新于 2021-02-13 09:44:31">2021-02-13</time></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div><article class="post-content" id="article-container"><link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/hint.css/2.4.1/hint.min.css"><p>我的一个python程序需要写一个界面,最终定的是逻辑使用python,界面使用electron进行开发,electron的逻辑是由node来解释执行的,所以我把python作为node的一个子线程,node进程和python进程之间使用socket进行通信.</p>
<h3 id="需求"><a href="#需求" class="headerlink" title="需求"></a>需求</h3><p>我需要一个进程等待另一个进程下达指令,接收到指令后,分析并执行,然后给出返回值</p>
<img src="image-20210206190449967.png" alt="image-20210206190449967" style="zoom: 67%;" />



<h3 id="原理"><a href="#原理" class="headerlink" title="原理"></a>原理</h3><p>socket的原理简单来说,就是插头和插座, 一个插座可以由任意一个插头插上,插上就可以导电了. 同样,在socket中分为服务器端和客户端,服务器端进行监听,服务端在需要的时候发送数据包到服务端,服务端处理请求,将返回值返回给客户端.</p>
<p>当然,socket的运行,是需要借用一个端口的,服务端基于端口进行监听,客户端向端口发送数据.</p>
<p>由于通信协议,这些数据在传输的时候是以字节进行传输的,在python中体现为byte类型,在node中体现为buffer,用这种类型确实可以方便我们精确控制每一个字节传输的内容,而且如果合理利用可以提高传输效率.但是我考虑到byte类型与顶层逻辑之间转换的麻烦,决定使用字符串进行传输,按utf8进行编码.</p>
<h3 id="代码"><a href="#代码" class="headerlink" title="代码"></a>代码</h3><p>服务端:</p>
<p>服务端处理数据,我设置了一个表示处理数据的函数analysis,这个函数接收一个字符串类型的参数,处理,并返回一个字符串类型的参数.</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 服务端代码 python版</span></span><br><span class="line"><span class="keyword">import</span> socket</span><br><span class="line"><span class="keyword">import</span> traceback</span><br><span class="line"><span class="keyword">import</span> time</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">analysis</span>(<span class="params">str_</span>):</span></span><br><span class="line">    print(str_)</span><br><span class="line">    <span class="keyword">return</span> <span class="string">&quot;hhh,&quot;</span>+str_</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">host = <span class="string">&quot;&quot;</span></span><br><span class="line">port = <span class="number">800</span></span><br><span class="line">address = (host, port)</span><br><span class="line">time_now = time.strftime(<span class="string">&quot;%Y-%m-%d %H:%S:%M&quot;</span>, time.localtime())</span><br><span class="line">s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)</span><br><span class="line">s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, <span class="number">1</span>)</span><br><span class="line">s.bind(address)</span><br><span class="line">s.listen(<span class="number">1</span>)</span><br><span class="line"></span><br><span class="line"><span class="keyword">while</span> <span class="literal">True</span>:</span><br><span class="line">    print(<span class="string">&quot;Waiting for connections...&quot;</span>)</span><br><span class="line">    <span class="keyword">try</span>:</span><br><span class="line">        client_connection, client_address = s.accept()</span><br><span class="line">    <span class="keyword">except</span> KeyboardInterrupt:</span><br><span class="line">        <span class="keyword">raise</span></span><br><span class="line">    <span class="keyword">except</span>:</span><br><span class="line">        traceback.print_exc()</span><br><span class="line">        <span class="keyword">continue</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">try</span>:</span><br><span class="line">        <span class="built_in">print</span> (<span class="string">&quot;Got connection from&quot;</span>, client_connection.getpeername())</span><br><span class="line">        <span class="keyword">while</span> <span class="literal">True</span>:</span><br><span class="line">            <span class="comment"># client_connection.settimeout(5)</span></span><br><span class="line">            buf = client_connection.recv(<span class="number">1024</span>)</span><br><span class="line">            <span class="keyword">if</span> <span class="built_in">len</span>(buf) == <span class="number">0</span>: <span class="comment"># break,跳出while循环</span></span><br><span class="line">                <span class="keyword">break</span></span><br><span class="line">            <span class="keyword">else</span>:</span><br><span class="line">                client_connection.send(<span class="built_in">bytes</span>(analysis(buf.decode()), encoding=<span class="string">&quot;utf8&quot;</span>))  </span><br><span class="line">    <span class="keyword">except</span> (KeyboardInterrupt, SystemError):</span><br><span class="line">        <span class="keyword">raise</span></span><br><span class="line">    <span class="keyword">except</span>:</span><br><span class="line">        traceback.print_exc()</span><br><span class="line"></span><br><span class="line"><span class="keyword">try</span>:</span><br><span class="line">    client_connection.close()</span><br><span class="line"><span class="keyword">except</span> KeyboardInterrupt:</span><br><span class="line">    <span class="keyword">raise</span></span><br><span class="line"><span class="keyword">except</span>:</span><br><span class="line">    traceback.print_exc()</span><br></pre></td></tr></table></figure>



<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 服务端代码,node版</span></span><br><span class="line"><span class="comment">// 1 引入模块</span></span><br><span class="line"><span class="keyword">const</span> net = <span class="built_in">require</span>(<span class="string">&quot;net&quot;</span>);</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> analysis = <span class="function"><span class="keyword">function</span>(<span class="params">str_</span>)</span>&#123;</span><br><span class="line">  <span class="keyword">return</span> <span class="string">&quot;hhh, &quot;</span>+ str_;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 2 创建服务器</span></span><br><span class="line"><span class="keyword">let</span> clientArr = [];</span><br><span class="line"><span class="keyword">const</span> server = net.createServer();</span><br><span class="line"><span class="comment">// 3 绑定链接事件</span></span><br><span class="line">server.on(<span class="string">&quot;connection&quot;</span>, <span class="function">(<span class="params">person</span>) =&gt;</span> &#123;</span><br><span class="line">  <span class="built_in">console</span>.log(clientArr.length);</span><br><span class="line">  <span class="comment">// 记录链接的进程</span></span><br><span class="line">  person.id = clientArr.length;</span><br><span class="line">  clientArr.push(person);</span><br><span class="line">  person.setEncoding(<span class="string">&quot;utf8&quot;</span>);</span><br><span class="line">  <span class="comment">// 客户socket进程绑定事件</span></span><br><span class="line">  person.on(<span class="string">&quot;data&quot;</span>, <span class="function">(<span class="params">chunk</span>) =&gt;</span> &#123;</span><br><span class="line">    clientArr.forEach(<span class="function">(<span class="params">val</span>) =&gt;</span> &#123;</span><br><span class="line">      <span class="comment">// 数据写入全部客户进程中</span></span><br><span class="line">      <span class="comment">//////////// 数据在这里处理</span></span><br><span class="line">      val.write(analysis(chunk));</span><br><span class="line">    &#125;);</span><br><span class="line">  &#125;);</span><br><span class="line">  person.on(<span class="string">&quot;close&quot;</span>, <span class="function">(<span class="params">p1</span>) =&gt;</span> &#123;</span><br><span class="line">    clientArr[p1.id] = <span class="literal">null</span>;</span><br><span class="line">  &#125;);</span><br><span class="line">  person.on(<span class="string">&quot;error&quot;</span>, <span class="function">(<span class="params">p1</span>) =&gt;</span> &#123;</span><br><span class="line">    clientArr[p1.id] = <span class="literal">null</span>;</span><br><span class="line">  &#125;);</span><br><span class="line">&#125;);</span><br><span class="line">server.listen(<span class="number">800</span>);</span><br></pre></td></tr></table></figure>


<p>客户端:</p>
<p>客户端由一个csend函数,csend函数唯一的参数就是发送的数据,返回值是从服务器端返回的值</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 客户端代码, python版</span></span><br><span class="line"><span class="keyword">import</span> socket</span><br><span class="line"><span class="keyword">import</span> sys</span><br><span class="line"></span><br><span class="line">host = <span class="string">&quot;localhost&quot;</span></span><br><span class="line">port = <span class="number">800</span></span><br><span class="line">address = (host, port)</span><br><span class="line"></span><br><span class="line">s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)</span><br><span class="line">s.connect(address)</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">csend</span>(<span class="params">mes</span>):</span></span><br><span class="line">    s.send(<span class="built_in">bytes</span>(mes, encoding=<span class="string">&quot;utf8&quot;</span>))</span><br><span class="line">    <span class="keyword">try</span>:</span><br><span class="line">        buf = s.recv(<span class="number">1024</span>)</span><br><span class="line">        <span class="keyword">return</span> buf.decode()</span><br><span class="line">    <span class="keyword">except</span> e:</span><br><span class="line">        <span class="built_in">print</span> (<span class="string">&quot;Error receiving :&quot;</span>, e)</span><br><span class="line">        <span class="keyword">return</span> <span class="string">&quot;&quot;</span></span><br><span class="line">        <span class="comment">#sys.exit(1) # 终止程序用</span></span><br><span class="line"></span><br><span class="line">mes = <span class="string">&quot;hello world&quot;</span></span><br><span class="line">print(csend(mes))</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">s.shutdown(socket.SHUT_WR)</span><br><span class="line">s.close()</span><br></pre></td></tr></table></figure>


<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 客户端代码, node版</span></span><br><span class="line"><span class="comment">// 1 引入模块</span></span><br><span class="line"><span class="keyword">const</span> net = <span class="built_in">require</span>(<span class="string">&quot;net&quot;</span>);</span><br><span class="line"><span class="keyword">const</span> readline = <span class="built_in">require</span>(<span class="string">&quot;readline&quot;</span>);</span><br><span class="line"><span class="comment">// 2 创建套接字和输入输出命令行</span></span><br><span class="line"><span class="keyword">let</span> rl = readline.createInterface(&#123;</span><br><span class="line">  <span class="comment">// 调用std接口</span></span><br><span class="line">  input: process.stdin,</span><br><span class="line">  output: process.stdout,</span><br><span class="line">&#125;);</span><br><span class="line"><span class="keyword">let</span> client = <span class="keyword">new</span> net.Socket();</span><br><span class="line"><span class="comment">// 3 链接</span></span><br><span class="line">client.connect(<span class="number">800</span>, <span class="string">&quot;localhost&quot;</span>);</span><br><span class="line"></span><br><span class="line">client.setEncoding(<span class="string">&quot;utf8&quot;</span>);</span><br><span class="line"><span class="comment">// 绑定输io流事件,获取输入输出字符</span></span><br><span class="line"><span class="comment">// rl.on(&#x27;line&#x27;,(mes)=&gt;&#123;</span></span><br><span class="line"><span class="comment">// client.write(mes);</span></span><br><span class="line"><span class="comment">// &#125;)</span></span><br><span class="line"></span><br><span class="line">client.on(<span class="string">&#x27;data&#x27;</span>, <span class="function">(<span class="params">data</span>) =&gt;</span> &#123;</span><br><span class="line">  <span class="built_in">console</span>.log(data)</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line">client.on(<span class="string">&quot;error&quot;</span>, <span class="function">(<span class="params">e</span>) =&gt;</span> &#123;</span><br><span class="line">  <span class="built_in">console</span>.log(e.message);</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">csend</span>(<span class="params">mes</span>) </span>&#123;</span><br><span class="line">  client.write(mes);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">csend(<span class="string">&quot;hello world&quot;</span>);</span><br></pre></td></tr></table></figure>
<h3 id="用法"><a href="#用法" class="headerlink" title="用法"></a>用法</h3><p>服务端二选一,运行起来,然后执行客户端代码,客户端也是二选一,运行之后控制台会有输出</p>
<h3 id="补充"><a href="#补充" class="headerlink" title="补充"></a>补充</h3><p>由于我的python进程需要执行很长时间,因此python部分加入了多线程,一下就是举个例子,似乎不是那么有通用性</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> socket</span><br><span class="line"><span class="keyword">import</span> traceback</span><br><span class="line"><span class="keyword">import</span> time</span><br><span class="line"><span class="keyword">import</span> threading</span><br><span class="line"><span class="keyword">import</span> json</span><br><span class="line"></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">此文件作为python后台的控制中心</span></span><br><span class="line"><span class="string">接收并处理 来自前端和子python进程 的指令 并 启动子线程完成任务</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">注,暂时子python进程可以直接向前端发送数据,也可以向此父进程发送数据再转发, 看开发者心情</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">接收信息格式: json字符串</span></span><br><span class="line"><span class="string">&#123;</span></span><br><span class="line"><span class="string">    &quot;command&quot;:&quot;online_check_in&quot; // 必须</span></span><br><span class="line"><span class="string">    &quot;其他&quot;:...  // 其他根据情况选择</span></span><br><span class="line"><span class="string">&#125;</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">子进程未设置推出,估计会自动退出,后续解决</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">thread_template</span>(<span class="params">threading.Thread</span>):</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__init__</span>(<span class="params">self, threadID, name, get</span>):</span></span><br><span class="line">        threading.Thread.__init__(self)</span><br><span class="line">        self.threadID = threadID</span><br><span class="line">        self.name = name</span><br><span class="line">        self.get = get</span><br><span class="line">        self.command = get.get(<span class="string">&quot;command&quot;</span>)</span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">run</span>(<span class="params">self</span>):</span></span><br><span class="line">        <span class="built_in">print</span> (<span class="string">&quot;开启线程： &quot;</span> + self.name)</span><br><span class="line">        <span class="built_in">print</span> (<span class="string">&quot;此线程执行的指令为&quot;</span>, self.command)</span><br><span class="line">        <span class="comment"># 此处的get为字典类型,具有command字段,其他字段由传入决定</span></span><br><span class="line">        <span class="keyword">if</span> self.command == <span class="string">&quot;online_check_in&quot;</span>:</span><br><span class="line">            <span class="comment"># camera.m()</span></span><br><span class="line">            <span class="comment">####################<span class="doctag">TODO:</span> 在此处执行此时的方法,可以用全局方法,推荐使用类方法</span></span><br><span class="line">            <span class="comment">#<span class="doctag">TODO:</span>执行线上点名的python脚本</span></span><br><span class="line">            <span class="keyword">pass</span></span><br><span class="line">        <span class="keyword">elif</span> self.command == <span class="string">&quot;offline_check_in&quot;</span>:</span><br><span class="line">            <span class="comment"># todo:执行线下点名的python脚本</span></span><br><span class="line">            <span class="keyword">pass</span></span><br><span class="line">        <span class="keyword">elif</span> self.command == <span class="string">&quot;online_check_behavior&quot;</span>:</span><br><span class="line">            <span class="comment"># todo:执行线上行为检测的python脚本</span></span><br><span class="line">            <span class="keyword">pass</span></span><br><span class="line">        <span class="keyword">elif</span> self.command == <span class="string">&quot;offline_check_behavior_danger&quot;</span>:</span><br><span class="line">            <span class="comment"># todo:执行线下危险行为检测的python脚本</span></span><br><span class="line">            <span class="keyword">pass</span></span><br><span class="line">        <span class="keyword">elif</span> self.command == <span class="string">&quot;offline_check_behavior_state&quot;</span>:</span><br><span class="line">            <span class="comment"># todo:执行线下状态检测的python脚本</span></span><br><span class="line">            <span class="keyword">pass</span></span><br><span class="line">        <span class="keyword">elif</span> self.command == <span class="string">&quot;record_face&quot;</span>:</span><br><span class="line">            camera.m()</span><br><span class="line">            <span class="keyword">pass</span></span><br><span class="line">        <span class="keyword">else</span>:</span><br><span class="line">            print(<span class="string">&quot;出现了意想不到的情况&quot;</span>)</span><br><span class="line">            <span class="keyword">pass</span></span><br><span class="line">        <span class="comment"># 获取锁，用于线程同步</span></span><br><span class="line">        <span class="comment"># threadLock.acquire()</span></span><br><span class="line">        self.print_time(self.name, self.counter, <span class="number">3</span>)</span><br><span class="line">        <span class="comment"># 释放锁，开启下一个线程</span></span><br><span class="line">        <span class="comment"># threadLock.release()</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">print_time</span>(<span class="params">self, threadName, delay, counter</span>):</span></span><br><span class="line">        <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">3</span>):</span><br><span class="line">            print(self.threadID, time.gmtime())</span><br><span class="line">            time.sleep(<span class="number">1</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 锁</span></span><br><span class="line"><span class="comment"># </span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">analysis</span>(<span class="params">str_</span>):</span></span><br><span class="line">    get = json.load(str_)</span><br><span class="line">    <span class="keyword">if</span> <span class="keyword">not</span> get.get(<span class="string">&quot;command&quot;</span>):</span><br><span class="line">        print(<span class="string">&quot;接收数据不包含指令,内容为&quot;</span>,str_)</span><br><span class="line">        <span class="keyword">return</span></span><br><span class="line">    th = thread_template(thread_id_count, get.get(<span class="string">&quot;command&quot;</span>), get)</span><br><span class="line">    threads.append(th)</span><br><span class="line">    th.start()</span><br><span class="line">    <span class="keyword">return</span> <span class="string">&quot;hhh,&quot;</span>+str_</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">host = <span class="string">&quot;&quot;</span></span><br><span class="line">port = <span class="number">800</span></span><br><span class="line">address = (host, port)</span><br><span class="line">time_now = time.strftime(<span class="string">&quot;%Y-%m-%d %H:%S:%M&quot;</span>, time.localtime())</span><br><span class="line">s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)</span><br><span class="line">s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, <span class="number">1</span>)</span><br><span class="line">s.bind(address)</span><br><span class="line">s.listen(<span class="number">1</span>)</span><br><span class="line"></span><br><span class="line">threads = [] <span class="comment"># 进程们</span></span><br><span class="line">threadLock = threading.Lock() <span class="comment"># 锁</span></span><br><span class="line">thread_id_count = <span class="number">0</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">while</span> <span class="literal">True</span>:</span><br><span class="line">    print(<span class="string">&quot;Waiting for connections...&quot;</span>)</span><br><span class="line">    <span class="keyword">try</span>:</span><br><span class="line">        client_connection, client_address = s.accept()</span><br><span class="line">    <span class="keyword">except</span> KeyboardInterrupt:</span><br><span class="line">        <span class="keyword">raise</span></span><br><span class="line">    <span class="keyword">except</span>:</span><br><span class="line">        traceback.print_exc()</span><br><span class="line">        <span class="keyword">continue</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">try</span>:</span><br><span class="line">        <span class="built_in">print</span> (<span class="string">&quot;Got connection from&quot;</span>, client_connection.getpeername())</span><br><span class="line">        <span class="keyword">while</span> <span class="literal">True</span>:</span><br><span class="line">            <span class="comment"># client_connection.settimeout(5)</span></span><br><span class="line">            buf = client_connection.recv(<span class="number">1024</span>)</span><br><span class="line">            <span class="keyword">if</span> <span class="built_in">len</span>(buf) == <span class="number">0</span>: <span class="comment"># break,跳出while循环</span></span><br><span class="line">                <span class="keyword">break</span></span><br><span class="line">            <span class="keyword">else</span>:</span><br><span class="line">                client_connection.send(<span class="built_in">bytes</span>(analysis(buf.decode()), encoding=<span class="string">&quot;utf8&quot;</span>))  </span><br><span class="line">    <span class="keyword">except</span> (KeyboardInterrupt, SystemError):</span><br><span class="line">        <span class="keyword">raise</span></span><br><span class="line">    <span class="keyword">except</span>:</span><br><span class="line">        traceback.print_exc()</span><br><span class="line"></span><br><span class="line"><span class="keyword">try</span>:</span><br><span class="line">    client_connection.close()</span><br><span class="line"><span class="keyword">except</span> KeyboardInterrupt:</span><br><span class="line">    <span class="keyword">raise</span></span><br><span class="line"><span class="keyword">except</span>:</span><br><span class="line">    traceback.print_exc()</span><br></pre></td></tr></table></figure>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">boshen</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://www.acbs.top/new/2021/02/06/%E9%80%9A%E8%BF%87socket%E8%BF%9B%E8%A1%8C%E6%9C%AC%E5%9C%B0%E7%9A%84%E8%BF%9B%E7%A8%8B%E9%97%B4%E9%80%9A%E4%BF%A1/">http://www.acbs.top/new/2021/02/06/%E9%80%9A%E8%BF%87socket%E8%BF%9B%E8%A1%8C%E6%9C%AC%E5%9C%B0%E7%9A%84%E8%BF%9B%E7%A8%8B%E9%97%B4%E9%80%9A%E4%BF%A1/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://www.acbs.top/new" target="_blank">ACBS</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/new/tags/python/">python</a><a class="post-meta__tags" href="/new/tags/socket/">socket</a></div><div class="post_share"><div class="social-share" data-image="/new/img/orange.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/new/2021/02/07/%E5%91%BD%E4%BB%A4%E8%A1%8C%E4%B8%AD%E4%BD%BF%E7%94%A8%E4%BB%A3%E7%90%86/"><img class="prev-cover" src="/new/img/orange.jpg" onerror="onerror=null;src='/new/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">命令行中使用代理</div></div></a></div><div class="next-post pull-right"><a href="/new/2021/02/04/%E8%B7%AF%E5%BE%84%E8%BF%87%E9%95%BF/"><img class="next-cover" src="/new/img/orange.jpg" onerror="onerror=null;src='/new/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">Windows10路径过长 解决办法</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span> 相关推荐</span></div><div class="relatedPosts-list"><div><a href="/new/2021/02/04/Python国内镜像/" title="Python 国内镜像"><img class="cover" src="/new/img/orange.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-02-04</div><div class="title">Python 国内镜像</div></div></a></div><div><a href="/new/2021/02/10/Right-Menu-To-Copy-Path-principle/" title="在右键菜单中添加复制文件名或者路径的功能(原理)"><img class="cover" src="/new/img/orange.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-02-10</div><div class="title">在右键菜单中添加复制文件名或者路径的功能(原理)</div></div></a></div><div><a href="/new/2021/02/10/Right-Menu-To-Copy-Path/" title="在右键菜单中添加复制文件名或者路径的功能(使用说明)"><img class="cover" src="/new/img/orange.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-02-10</div><div class="title">在右键菜单中添加复制文件名或者路径的功能(使用说明)</div></div></a></div><div><a href="/new/2021/02/12/pyqt5调用ui文件作为主界面/" title="pyqt5调用ui文件作为主界面"><img class="cover" src="/new/img/orange.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-02-12</div><div class="title">pyqt5调用ui文件作为主界面</div></div></a></div><div><a href="/new/2021/02/13/使用pyuic5工具将调用ui文件转换为python类/" title="使用pyuic5工具将调用ui文件转换为python类"><img class="cover" src="/new/img/orange.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-02-13</div><div class="title">使用pyuic5工具将调用ui文件转换为python类</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="card-info-avatar is-center"><img class="avatar-img" src="/new/img/touxiang.png" onerror="this.onerror=null;this.src='/new/img/friend_404.gif'" alt="avatar"/><div class="author-info__name">boshen</div><div class="author-info__description"></div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/new/archives/"><div class="headline">文章</div><div class="length-num">12</div></a></div><div class="card-info-data-item is-center"><a href="/new/tags/"><div class="headline">标签</div><div class="length-num">7</div></a></div><div class="card-info-data-item is-center"><a href="/new/categories/"><div class="headline">分类</div><div class="length-num">2</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/zephms"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/zephms" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="mailto:ab@dfgh.asia" target="_blank" title="Email"><i class="fas fa-envelope"></i></a><a class="social-icon" href="/new/info/qq" target="_blank" title="QQ"><i class="iconfont icon-QQ1"></i></a></div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%9C%80%E6%B1%82"><span class="toc-number">1.</span> <span class="toc-text">需求</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%8E%9F%E7%90%86"><span class="toc-number">2.</span> <span class="toc-text">原理</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BB%A3%E7%A0%81"><span class="toc-number">3.</span> <span class="toc-text">代码</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%94%A8%E6%B3%95"><span class="toc-number">4.</span> <span class="toc-text">用法</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%A1%A5%E5%85%85"><span class="toc-number">5.</span> <span class="toc-text">补充</span></a></li></ol></div></div></div></div></main><footer id="footer"></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/new/js/utils.js"></script><script src="/new/js/main.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>